<template>
	<el-container>
		<el-main class='x-main-edit'>
			<el-form ref="form" :rules="form_rules" :model="form" size="mini" label-width="15%">
				<el-tabs type="border-card" v-model="page_tag">
					<!---->
					<!---->
					<el-tab-pane :label="page_info.title" name="1">
						<el-form-item label="名称" prop="suser_name">
							<el-input class="x-input-60" v-model="form.suser_name"/>
						</el-form-item>
						<el-form-item label="手机号" prop="suser_phone">
							<el-input class="x-input-60" v-model="form.suser_phone"/>
						</el-form-item>
						<el-form-item label="KEY" prop="suser_key">
							<el-input type="textarea" :rows="5" class="x-input-60" v-model="form.suser_key"/>
							<div class="x-alert">
								<span>京东格式：pt_key=abczcvasdf;pt_pin=123;</span><br/>
								<span>过期时间：{{ form.suser_key_expire_date }}</span>
							</div>
						</el-form-item>
						<el-form-item v-if="page_info.share_code" label="助力码配置" prop="share_code">
							<!---->
							<!---->
							<!-- 助力码 -->
							<div class="item" v-for="(item,index) in page_info.share_code">
								<el-checkbox v-model="page_info.share_code[index].enable"/>
								{{ page_info.share_code[index].name }}
								<span v-if="page_info.share_code[index].enable">
									<el-input class="x-input-60" v-model="page_info.share_code[index].code"/>
								</span>
							</div>
							<!---->
							<!---->
							<!---->
						</el-form-item>
						<el-form-item label="状态" prop="suser_enable">
							<el-switch v-model="form.suser_enable"
									   active-color="#13ce66"
									   :active-value="1" active-text="生效"
									   :inactive-value="0" inactive-text="失效">
							</el-switch>
						</el-form-item>
						<el-form-item label="请求链接" prop="suser_task_api_url">
							<div class="x-alert">
								<span>秒杀任务运行的请求链接</span>
							</div>
							<el-input type="textarea" :rows="5" class="x-input-60" v-model="form.suser_task_api_url"/>
						</el-form-item>
						<el-form-item label="排序" prop="suser_order">
							<el-input-number v-model="form.suser_order" :step="1"></el-input-number>
						</el-form-item>
					</el-tab-pane>
					<!---->
					<!---->
					<el-tab-pane v-if="false" label="模板" name="2">
						<el-form-item label="应用模板" prop="reply_app_file" ref="reply_app_file">
							<el-col :span="6">
								<el-input v-model="form.reply_app_file" placeholder="默认：t_001"/>
							</el-col>
						</el-form-item>
					</el-tab-pane>
					<!---->
					<!---->
				</el-tabs>
				<!---->
				<!---->
			</el-form>
			<!---->
			<!---->
			<!-- 按钮部分 -->
			<div class="save_wrap">
				<el-button @click="g_page.funcBack" size="mini">返回</el-button>
				<el-button type="success" @click="g_page.funcSave" size="mini">保存</el-button>
				<el-button v-if="page_info.is_admin_edit" type="primary" @click="funcUpdateShareCodeApi" size="mini">
					更新助力码
				</el-button>
				<el-checkbox v-if="page_info.is_admin_edit" style="margin-left: 10px;" label="保存后停留" v-model="checked"/>
			</div>
			<!---->
			<!---->
			<!---->
		</el-main>
	</el-container>
</template>

<script>
	export default {
		data() {
			let page_data = { dialogVisible: false }
			//
			page_data = this.g_cc.funcGetInitData(page_data)
			//
			return page_data
		},
		mounted() {
			console.log('mounted', this._uid)
			console.log(this.$route.query)

			this.g_page.funcSetVue(this)
			//
			this.g_page.funcSetApiUrlEdit('/xadmin/sh/sh__user__edit')
			this.g_page.funcSetApiUrlSave('/xadmin/sh/sh__user__edit/save')
			let page = this
			//验证
			this.form_rules = {
				__test: [{
					required: true,
					message: '请输入原密码',
					trigger: 'blur'
				}]
			}

			let data = this.$route.query
			this.g_page.funcEdit(data)
		},
		methods: {
			//保存之前
			funcSaveBefore(data) {
				console.log('funcSaveBefore', data)

				data.share_code = JSON.stringify(this.page_info.share_code)

				return data
			},
			funcUpdateShareCodeApi() {
				let page = this
				this.g_cc.func_axios({
					url: '/xadmin/sh/sh__user__list/funcUpdateShareCode',
					data: {
						id: page.form.id
					},
					success: (res) => {
						//
						if (res.data.errcode == 0) {
							this.g_cc.func_alert('成功')
						} else {
							this.g_cc.func_alert(res.data.errmsg, 'error')
						}
					}
					//
				})
			}
			////////////////
		}
	}
</script>

<style scoped>
	.item {
		margin-bottom: 5px;
	}
</style>
